// banner轮播已在前面定义

// 初始化宫格分页滑动
new Swiper('.grid-swiper', {
    loop: false,
    pagination: {
        el: '.swiper-pagination',
    },
});
let currentPage = 1;
$('#loadMoreDiv').on('click', function () {
    const $loadMore = $(this);
    if ($loadMore.hasClass('disabled')) return;

    currentPage++;
    $loadMore.text('加载中...');

    $.ajax({
        url: '/ajaxList',
        type: 'GET',
        data: {
            page: currentPage
        },
        success: function (res) {
            if (res.code === 1 && res.data.length > 0) {
                let html = '';
                res.data.forEach(function (item) {
                    html += `
                    <div class="news-info">
                        <div class="news-text">
                            <div class="news-title">
                                <a href="/ndetail/${item.id}" title="${item.title}">${item.title}</a>
                            </div>
                            <div class="news-time">${item.show_time}</div>
                        </div>
                        <a href="/ndetail/${item.id}" class="news-img-link">
                            <img src="${item.thumb}" alt="${item.title}" />
                        </a>
                    </div>
                `;
                });
                $('#loadMoreDiv').before(html);
                $loadMore.text('点击查看更多');
            } else {
                $loadMore.text('没有更多内容了').addClass('disabled');
            }
        },
        error: function () {
            $loadMore.text('加载失败，请重试');
        }
    });
});

